#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <vector>

using namespace std;

const int SZ = 15;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};

bool Good(char c)
{
	if (c == '1' || c == '2' || c == 'H' || c == '.' || c == '#') return true;
	return false;
}

char field[SZ][SZ];
int num[SZ][SZ];
vector<pair<int, int> > hives;
vector<pair<int, pair<int, int> > > moves;

int main(int argc, char *argv[])
{
    srand((unsigned)time(NULL));
    int we = atoi(argv[1]);
	char enemyhive = (char)(3 - we + '0');
    while (1)
    {
        for (int i = 0; i < SZ; i++)
        {
            for (int j = 0; j < SZ; j++)
            {
            	char c = getchar();
            	while (!Good(c)) c = getchar();
            	field[i][j] = c;
            }
        }
        for (int i = 0; i < SZ; i++)
        {
        	for (int j = 0; j < SZ; j++)
        	{
        		scanf("%d", &num[i][j]);
        	}
        }
		hives.clear();
		moves.clear();
		for (int i = 0; i < SZ; i++)
		{
			for (int j = 0; j < SZ; j++)
			{
				if (field[i][j] == 'H' || field[i][j] == enemyhive)
				{
					hives.push_back(make_pair(i, j));
				}
			}
		}
		if (hives.size() > 0)
		{
			for (int i = 0; i < SZ; i++)
			{
				for (int j = 0; j < SZ; j++)
				{
					if (num[i][j] > 0)
					{
						unsigned int k, mk;
						mk = 0;
						int md = 2000000000;
						for (k = 0; k < hives.size(); k++)
						{
							if (abs(hives[k].first - i) + abs(hives[k].second - j) < md)
							{
								md = abs(hives[k].first - i) + abs(hives[k].second - j);
								mk = k;
							}
						}
						vector<int> dirs;
						md = 2000000000;
						for (k = 0; k < 4; k++)
						{
							int ni, nj;
							ni = i + di[k];
							nj = j + dj[k];
							int cd = abs(ni - hives[mk].first) + abs(nj - hives[mk].second);
							if (cd < md)
							{
								md = cd;
								dirs.clear();
								dirs.push_back(k);
							}
							else if (cd == md) dirs.push_back(k);
						}
						moves.push_back(make_pair(dirs[rand() % dirs.size()], make_pair(i, j)));
					}
				}
			}           
		}
		printf("%d\n", moves.size());
		for (unsigned int i = 0; i < moves.size(); i++)
		{
			printf("%d %d %d %d\n", moves[i].second.first, moves[i].second.second, moves[i].first, 
									num[moves[i].second.first][moves[i].second.second]);
		}
		printf("\n");
		fflush(stdout);
    }
    return 0;
}
